<template>
	<!-- 终极押题 -->
	<view class="pd-30">
		<u-navbar back-icon-color="#fff" title-color="#fff" title="终极押题" :border-bottom="false"></u-navbar>
		<!-- <my-scroll-view scroll-y refresher-enabled :init="init"> -->
		<my-paper-list-item
			@click.native="viewResult(paper, 'startYaTi', false)"
			answer
			score
			@start-exam="startYaTi"
			:key="paper.paperid"
			v-for="paper in dataList.list"
			:item="paper"
		></my-paper-list-item>
		<!-- </my-scroll-view> -->
		<u-loadmore v-show="isShowLoadMore" icon-type="flower" bg-color="#f5f5f5" :status="status" @loadmore="getPageData()" :margin-top="20" />
		<my-empty v-if="isEmpty"></my-empty>
	</view>
</template>

<script>
import exam from '../../mixins/exam.js';
export default {
	mixins: [exam],
	data() {
		return {
			status: 'loadmore',
			dataList: {
				list: [],
				pageNo: 1,
				isLastPage: false
			}
		};
	},
	onLoad() {
		this.init();
	},
	onReachBottom() {
		if (!this.dataList.isLastPage) this.getPageData();
	},
	computed: {
		list() {
			return this.dataList.list;
		},
		isLastPage() {
			return this.dataList.isLastPage;
		}
	},
	methods: {
		init() {
			this.status = 'loadmore';
			this.dataList = {
				list: [],
				pageNo: 1,
				isLastPage: false
			};
			return this.getPageData();
		},
		getPageData() {
			const { pageNo } = this.dataList;
			this.status = 'loading';
			return new Promise((resolve, reject) => {
				this.request
					.post('/app/proposition/getPropositionList', {
						papertype: 2,
						pageNo
					})
					.then(res => {
						const { list, isLastPage } = res;
						this.dataList.list = this.dataList.list.concat(list);
						this.dataList.isLastPage = isLastPage;
						if (!isLastPage) this.dataList.pageNo++;
						else this.status = 'nomore';
						resolve();
					})
					.catch(reject)
					.finally(() => {
						!this.dataList.isLastPage && (this.status = 'loadmore');
					});
			});
		}
	}
};
</script>
<style>
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss"></style>
